//
// Created by moonlight on 25-7-30.
//
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <ctime>
#define CHEHUA 0
#define MEISHU 1
#define YANFA 2
using namespace std;
class Worker {
public:
    string name;
    int salary;
};

void createWorkers(vector<Worker> &workers) {
    string nameSeed = "ABCDEFGHIJ";
    for (int i = 0; i < 10; i++) {
        Worker worker;
        worker.name = "员工";
        worker.name += nameSeed[i];
        worker.salary = rand() % 10001+10000;
        workers.push_back(worker);
    }
}

void setGroup(vector<Worker> & workervector,multimap<int, Worker> &deptmap) {
    for (vector<Worker>::iterator it = workervector.begin(); it != workervector.end(); it++) {
        //随机部门的编号
        int deptId = rand() % 3;
        //将员工插入到分组中
        deptmap.insert(make_pair(deptId, *it));
    }
}

void showWorkerByGroup(const multimap<int, Worker> & deptmap) {
    cout << "策划部门:" << endl;
    multimap<int, Worker>::const_iterator iterator = deptmap.find(CHEHUA);
    int count = deptmap.count(CHEHUA);
    int index = 0;
    for (; iterator != deptmap.end() && index < count; iterator++, index++) {
        cout <<"name: "<< iterator->second.name << " " <<"salary: "<<iterator->second.salary << endl;
    }
    cout << "美术部门:" << endl;
    count = deptmap.count(MEISHU);
    index = 0;
    for (; iterator != deptmap.end() && index < count; iterator++, index++) {
        cout <<"name: "<< iterator->second.name << " " <<"salary: "<<iterator->second.salary << endl;
    }
    cout << "研发部门:" << endl;
    count = deptmap.count(YANFA);
    index = 0;
    for (; iterator != deptmap.end() && index < count; iterator++, index++) {
        cout <<"name: "<< iterator->second.name << " " <<"salary: "<<iterator->second.salary << endl;
    }
}

int main() {
    srand((unsigned int)time(NULL));
    //1.创建员工
    vector<Worker> workers;
    createWorkers(workers);
    //2.分组
    multimap<int, Worker> deptmap;
    setGroup(workers,deptmap);
    //分组显示
    showWorkerByGroup(deptmap);
    // for (vector<Worker>::iterator it = workers.begin(); it != workers.end(); it++) {
    //     cout <<"name: "<< it->name <<" ";
    //     cout <<"salary: "<< it->salary << endl;
    // }
    return 0;
}
